<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 引入easyui的样式 -->
<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/themes/default/easyui.css">
<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/themes/icon.css">
<!-- js文件 -->
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>

</head>
<script type="text/javascript">
//页面加载时发送请求
$(function(){
	$('#hj').datagrid({
		url:"SelTeacherJob",
		queryParams: {			
			tid:"${sessionScope.user.tid}",
		}
	});
});

$(function(){
	//更改底部工具栏 getPager返回页面对象
	var pager = $('#hj').datagrid('getPager');	
	  pager.pagination({
		pageList: [10,20,30]
	});
})
//作业评分
function formatOper(val,row,index){  
   return '<a href="#" onclick="editUser('+index+')">评分</a>';     
    }  
function editUser(index){  
    $('#hj').datagrid('selectRow',index);
    var row = $('#hj').datagrid('getSelected');  
    if (row){  
        $('#dlg').dialog('open').dialog('setTitle','审核学生作业');  
        $('#fm').form('load',row);  
        $('#jd').hide();        
		 var job =$("#hj").datagrid('getSelected');
		 $("#jrid").textbox('setValue',job.jrid);
		 $("#jname").textbox('setValue',job.jname);
		 $("#endTime").textbox('setValue',job.endTime);
		 $("#sname").textbox('setValue',job.sname);
		 $("#jsname").textbox('setValue',job.jsname);
		 $("#answer").textbox('setValue',job.answer);
		 $("#grade").textbox('setValue',"");
     }
  }		 
		 $(function(){
			 $("#ok").click(function(){
				 var jrid = $("#jrid").val();
				 var grade = $("#grade").val();
				 var uid =${user.uid};
				 if(grade!=""){
						$.ajax({	   				
			   				type:"post",
			   				url:"audit",
			   				data:{"grade":grade,"jrid":jrid,"uid":uid},
			   				dataType:"text",
			   				success:function(data){
					    		if(data=="true"){
					    			$.messager.alert('提示','评分成功','info',function(){
					    				$('#hj').datagrid('reload'); 
					    				$('#dlg').dialog('close')
						    			}); 			    							 	    					    			
					    		  }else{
					    			  $.messager.alert('提示','评分失败','info',function(){
						    				$('#hj').datagrid('reload'); 
					    			  });
					    		  }
					    	}    		   		
			    	})
				 }else{
	    			  $.messager.alert('提示','未评分','info',function(){
		    				$('#hj').datagrid('reload'); 
	    			  });
				 }

		 })
	 })
</script>
<body>
	 <table id="hj" title="审核作业" class="easyui-datagrid" method="post"
            toolbar="#toolbar" pagination="true" fit="true"  
            striped="true"  pageSize="10"
            rownumbers="true" fitColumns="true" border="false">         
        <thead>
			<tr> 
            	<th field="jrid" hidden="true" >作业记录编号</th>               
                <th field="jname" width="50" resizable="false">作业名字</th> 
                <th field="endTime" width="50" resizable="false">完成时间</th>  
                <th field="sname" width="50" resizable="false">学生名字</th>
                <th field="jsname" width="50" resizable="false">作业状态 </th>
                <th field="answer" width="50" resizable="false">学生答案 </th>
                <th data-options="field:'_operate',width:50,align:'center',formatter:formatOper">作业成绩</th>
            </tr>
        </thead>
    </table>
    
       <div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
            closed="true" buttons="#dlg-buttons">
        <div style="margin-left: 60px"> 
        <form id="fm" method="post" novalidate>
             <div class="fitem" id="jd">
                <label>作业编号:</label>
                <input id="jrid" class="easyui-textbox" disabled="true">
            </div>       
            <div class="fitem" id="na">
                <label>作业名字:</label>
                <input id="jname" class="easyui-textbox" disabled="true">
            </div>
            <div class="fitem" id="ag">
                <label>完成时间:</label>
                <input id="endTime" class="easyui-textbox" disabled="true">
            </div>
            <div class="fitem" id="ad">
                <label>学生名字:</label>
                <input id="sname" class="easyui-textbox" disabled="true">
            </div>
            <div class="fitem" id="nm">
                <label>完成状态:</label>
                <input id="jsname" class="easyui-textbox" disabled="true">
            </div>
            <div class="fitem" id="nm">
                <label>学生答案:</label>
                <input id="answer" class="easyui-textbox" disabled="true">
            </div>
            <div class="fitem" id="un">
                <label>作业成绩:</label>
                <input id="grade" class="easyui-textbox"
                required="required" missingMessage="请输入学生成绩">
            </div>
        </form>
       </div>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" style="width:90px;" id="ok" >保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" 
        onclick="javascript:$('#dlg').dialog('close')" style="width:90px;">取消</a>
    </div>
</body>
</html>